package com.example.bbang.service;

import com.example.bbang.entity.Order;
import com.example.bbang.entity.User;
import com.example.bbang.mapper.OrderMapper;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderService {
    @Resource
    OrderMapper orderMapper;


    public List<Order> getOrderById(String bname,Integer orderStatus) {

        return orderMapper.getOrderById(bname,orderStatus);
    }

    public Order addOrderById(Order order) {
         orderMapper.addOrderById(order);
         return order;
    }

    public Object getOrder() {        return orderMapper.getOrder();    }


    public void updateById(Order order) {
        orderMapper.updateById(order);
    }

    public void deleteById(Order order) {
        orderMapper.deleteById(order);
    }

    public void updateByName(Order order) {
        orderMapper.updateByName(order);
    }

    public List<Order> getOrderByState(Integer orderStatus,String username) {
        return orderMapper.getOrderByState(orderStatus,username);
    }

    public Integer countOrderByOrderStatus(String orderStatus) {
        return orderMapper.countOrderByOrderStatus(orderStatus);
    }

    public Integer countOrder() {
        return orderMapper.countOrder();
    }

    public Boolean grabTask(Long orderId,Long userId){
        Integer orderStatus = orderMapper.getOrderStatusByorderId(orderId);
        if(orderStatus==0){
            System.out.println("用户："+userId+"抢到了单");
            return true;
        }
        else return false;
    }

    public Boolean grabOrder(Long orderId,String bname){
        Integer orderStatus = orderMapper.getOrderStatusByorderId(orderId);
        if(orderStatus==0){
            System.out.println("用户："+bname+"抢到了单");
            return true;
        }
        else return false;
    }
}
